Protect hosted anonymous tunnels with ownership tokens#18
Closed
mmkal wants to merge 4 commits into
Closed
Conversation
commit: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fd12c6a. Configure here.
Contributor
Author
|
Superseded by #20, which now combines the hosted rate-limit, ownership-token, conflict-message, and admission-module changes in one review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds active-session ownership tokens for anonymous hosted
captun.shtunnels.Behavior:
captun-owner-tokenquery param orx-captun-owner-tokenheader409 Conflictwithout evicting the active tunnelcreateCaptunTunnelreturnsownerTokenand acceptsownerTokenfor intentional same-owner replacementownerTokenshapeFollow-up left out intentionally
Ownership is active-session only. Once the tunnel disconnects, the name is free for another anonymous token to claim. Persistent reservations, paid/custom names, active tunnel caps, byte/response caps, and edge throttles remain later hosted-safety work.
Verification
pnpm test -- test/worker.test.ts --testNamePattern 'ownership token|anonymous ownership|send an anonymous|reuse a returned'pnpm run checkpnpm testpnpm run buildCAPTUN_PUBLIC_E2E=1 pnpm vitest run test/public-hosted.test.tsNote
Medium Risk
Introduces new ownership-token enforcement on the hosted connect path, changing connection/eviction semantics and adding new 400/409 failure modes for
captun.shclients. While scoped to anonymous hosted mode (skipped for self-hosted and secret-protected setups), mistakes could block legitimate reconnects or allow unintended tunnel takeovers.Overview
Hosted
captun.shtunnels now require an anonymous ownership token on connect to prevent a second anonymous client from evicting an active tunnel by reusing the same subdomain.The client API (
createCaptunTunnel) now generates/propagates a token (query param by default, header override supported), returns it astunnel.ownerToken, and allows reusing it via anownerTokenoption; the hosted browser demo module was updated to match.On the Worker side,
CaptunServerShardnow tracks{ fetcher, ownerToken }per tunnel name: same-token reconnects replace the active session, different-token connects are rejected with409, and missing/invalid tokens return400only for anonymous hosted (CUSTOM_HOSTNAME=captun.shwithoutCAPTUN_SECRET). Tests were expanded to cover these cases and to assert self-hosted “last connection wins” remains unchanged.Reviewed by Cursor Bugbot for commit 0937d55. Bugbot is set up for automated code reviews on this repo. Configure here.